package org.apache.cassandra.server.impl;

import java.io.IOException;
import java.util.List;

import org.apache.cassandra.server.INodeConfigurationFactory;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import fr.aliasource.utils.RunnableExtensionLoader;

public class CassandraNodeFactory {

	private INodeConfigurationFactory ncf;
	private Logger logger = LoggerFactory.getLogger(getClass());

	public CassandraNodeFactory() {
		RunnableExtensionLoader<INodeConfigurationFactory> rel = new RunnableExtensionLoader<INodeConfigurationFactory>();
		List<INodeConfigurationFactory> ext = rel.loadExtensions(
				"org.apache.cassandra.server", "configuration", "configuration",
				"implementation");
		if (ext != null && ext.size() > 0) {
			ncf = ext.get(0);
			ncf.init();
		} else {
			logger.error("No plugin found for cassandra node configuration");
		}
	}

	public CassandraNode create() throws TTransportException, IOException {
		return new CassandraNode(ncf.get());
	}

}
